﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _2_1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        using (DataClassesDataContext mydata = new DataClassesDataContext())
        {

            var rd1 = from f in mydata.F_OUTPUT
                      join s in mydata.SF_CODE_FUNCTIONAREA on f.FUNCTION_REGION equals s.CODE
                      join c in mydata.CODE_OUTDIR on f.OUT_DIRECTION equals c.CODE
                      join v in mydata.CODE_VALLY on f.VALLEY_CODE equals v.CODE
                      join o in mydata.CODE_OUT_RULE on f.OUT_RULE equals o.OUTRULE_ID
                      where f.qiyeid == Convert.ToInt32(Session["qiyeid"])
                      where f.SERIAL == Convert.ToInt32(Session["PaiFangKou2-1"])
                      where s.P_TYPE == Convert.ToChar("1")
                      select new
                      {
                          pfkmc = f.OUT_NAME,
                          pfkbh = f.OUTPUT_CODE,
                          pfkwz = f.OUTPUT_POSITION,
                          pfkjd = f.XAIS == null ? "" : Convert.ToString(f.XAIS),
                          pfkwd = f.YAIS == null ? "" : Convert.ToString(f.YAIS),
                          gnqlb = s.NAME == null ? "" : s.NAME,
                          pfqx = c.DIRS == null ? "" : c.DIRS,
                          stmc = v.NAME == null ? "" : v.NAME,
                          wspfgl = o.OUT_RULE == null ? "" : o.OUT_RULE
                      };
            foreach (var r in rd1)
            {
                //*************排放口信息*********
                PFKMC.Text = r.pfkmc;
                PFKBH.Text = r.pfkbh;
                PFKWZ.Text = r.pfkwz;
                if (!(r.pfkjd == null || r.pfkjd == ""))
                {
                    JD.Text = r.pfkjd.ToString().Substring(0, 3) + "度" + r.pfkjd.ToString().Substring(3, 2) + "分" + r.pfkjd.ToString().Substring(5, 2) + "秒";
                }
                if (!(r.pfkwd == null || r.pfkwd == ""))
                {
                    WD.Text = r.pfkwd.ToString().Substring(0, 2) + "度" + r.pfkwd.ToString().Substring(2, 2) + "分" + r.pfkwd.ToString().Substring(4, 2) + "秒";
                }
                GNQLB.Text = r.gnqlb;
                PFQX.Text = r.pfqx;
                STMC.Text = r.stmc;
                PFGL.Text = r.wspfgl;

            }


            //************排放口除了污染物外申报数据*********
            var rd2 = from a in mydata.a01201_1
                      where a.qiyeid == Convert.ToInt32(Session["qiyeid"])
                      where a.DATA_MONTH == Convert.ToString(Session["ShenBaoNianDu"])
                      where a.SERIAL == Convert.ToInt32(Session["PaiFangKou2-1"])
                      select a;
            foreach (var r in rd2)
            {
                PFTS.Text = r.OUT_DAYS == null ? "" : string.Format("{0:0}", r.OUT_DAYS);
                PFSJ.Text = r.HOURS_DAY == null ? "" : string.Format("{0:0}", r.HOURS_DAY);
                WSPFL.Text = (r.SUM_COUNT == null || r.SUM_COUNT == 0) ? "" : string.Format("{0:#.####}", r.SUM_COUNT);
                DBPFL.Text =(r.REACH_CNT == null || r.REACH_CNT == 0) ? "" : string.Format("{0:#.####}", r.REACH_CNT);
                CBPFL.Text = (r.OVER_CNT == null || r.OVER_CNT == 0) ? "" : string.Format("{0:#.####}", r.OVER_CNT);

                //排放月份
                for (int i = 0; i < 12; i++)
                {
                    CheckBoxList1.Items[i].Selected = false;
                }
                string[] fh = new string[] { "," };
                string[] yf;
                string s = r.OUT_MONTH;
                if (r.OUT_MONTH != null && r.OUT_MONTH != "")
                {
                    yf = s.Split(fh, StringSplitOptions.None);

                    foreach (var cs in yf)
                    {
                        CheckBoxList1.Items[Convert.ToInt32(cs) - 1].Selected = true;
                    }
                }
            }



            //**********读取污染物数据*********** 
            Label[] HJ = new Label[] { this.HJ1, this.HJ2, this.HJ3, this.HJ4, this.HJ5, this.HJ6, this.HJ7, this.HJ8, this.HJ9, this.HJ10, this.HJ11, this.HJ12, this.HJ13, this.HJ14, this.HJ15, this.HJ16 };
            Label[] DB = new Label[] { this.DB1, this.DB2, this.DB3, this.DB4, this.DB5, this.DB6, this.DB7, this.DB8, this.DB9, this.DB10, this.DB11, this.DB12, this.DB13, this.DB14, this.DB15, this.DB16 };
            Label[] CB = new Label[] { this.CB1, this.CB2, this.CB3, this.CB4, this.CB5, this.CB6, this.CB7, this.CB8, this.CB9, this.CB10, this.CB11, this.CB12, this.CB13, this.CB14, this.CB15, this.CB16 };
            Label[] WRW = new Label[] { this.WRW1, this.WRW2, this.WRW3, this.WRW4, this.WRW5 };
            var rd3 = from a in mydata.a01201_2
                      join c in mydata.CODE_POLLUTION_TABLE on a.CODE equals c.CODE
                      where a.qiyeid == Convert.ToInt32(Session["qiyeid"])
                      where a.DATA_MONTH == Convert.ToString(Session["ShenBaoNianDu"])
                      where a.SERIAL == Convert.ToInt32(Session["PaiFangKou2-1"])
                      select new { a.POLLUTE_OUTCOUNT, a.REACH_COUNT, a.OVER_COUNT, a.SRKXH, c.NAME };

            int xh;
            foreach (var r in rd3)
            {
                xh = Convert.ToInt32(r.SRKXH) - 1;
                if (xh >= 11)
                {
                    WRW[xh - 11].Text = r.NAME == null ? "" : r.NAME;
                }
                HJ[xh].Text = r.POLLUTE_OUTCOUNT == null ? "" : string.Format("{0:#.####}", r.POLLUTE_OUTCOUNT);
                DB[xh].Text = r.REACH_COUNT == null ? "" : string.Format("{0:#.####}", r.REACH_COUNT);
                CB[xh].Text = r.OVER_COUNT == null ? "" : string.Format("{0:#.####}", r.OVER_COUNT);
            }
        }
    }





}